package model;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Course of Moodle site.
 *
 * @author UNI\kgp
 */
public class MoodleCourse implements Comparable<MoodleCourse> {

    private long id;
    private String fullname;
    private String shortname;
    private long categoryid;
    private long categorysortorder;
    private String idnumber = "";
    private String summary = "";
    private byte summaryformat = 1;
    private String format = "topics";
    private byte showgrades = 1;
    private int newsitems = 5;
    private long startdate;
    private int numsections = 0;
    private long maxbytes = 20971520;
    private byte showreports = 1;
    private byte visible = 1;
    private int hiddensections = 0;
    private byte groupmode = 2;
    private byte groupmodeforce = 1;
    private long defaultgroupingid = 0;
    private long timecreated;
    private long timemodified;
    private byte enablecompletion = 0;
    private byte completionnotify = 0;
    private String lang = "en";
    private String forcetheme = "";
    private List<CourseFormatOption> courseformatoptions = new ArrayList<CourseFormatOption>();

    public MoodleCourse() {
    }

    /**
     * Constructor with complete set of arguments-varibles.
     */
    public MoodleCourse(long id, String shortname, long categoryid, long categorysortorder,
            String fullname, String idnumber, String summary, byte summaryformat,
            String format, byte showgrades, int newsitems, long startdate,
            int numsections, long maxbytes, byte showreports, byte visible,
            int hiddensections, byte groupmode, byte groupmodeforce,
            long defaultgroupingid, long timecreated, long timemodified,
            byte enablecompletion, byte completionnotify, String lang, String forcetheme,
            List<CourseFormatOption> courseformatoptions) {
        this.id = id;
        this.shortname = shortname;
        this.categoryid = categoryid;
        this.categorysortorder = categorysortorder;
        this.fullname = fullname;
        this.idnumber = idnumber;
        this.summary = summary;
        this.summaryformat = summaryformat;
        this.format = format;
        this.showgrades = showgrades;
        this.newsitems = newsitems;
        this.startdate = startdate;
        this.numsections = numsections;
        this.maxbytes = maxbytes;
        this.showreports = showreports;
        this.visible = visible;
        this.hiddensections = hiddensections;
        this.groupmode = groupmode;
        this.groupmodeforce = groupmodeforce;
        this.defaultgroupingid = defaultgroupingid;
        this.timecreated = timecreated;
        this.timemodified = timemodified;
        this.enablecompletion = enablecompletion;
        this.completionnotify = completionnotify;
        this.lang = lang;
        this.forcetheme = forcetheme;
        this.courseformatoptions = courseformatoptions;
    }

    /**
     * Constructor with full set of paramenters for new course creation through Web service.
     */
    public MoodleCourse(String fullname, String shortname, long categoryid,
            String idnumber, String summary, byte summaryformat,
            String format, byte showgrades, int newsitems, long startdate,
            int numsections, long maxbytes, byte showreports, byte visible,
            int hiddensections, byte groupmode, byte groupmodeforce,
            long defaultgroupingid, byte enablecompletion, byte completionnotify,
            String lang, String forcetheme, List<CourseFormatOption> courseformatoptions) {
        this.fullname = fullname;
        this.shortname = shortname;
        this.categoryid = categoryid;
        this.idnumber = idnumber;
        this.summary = summary;
        this.summaryformat = summaryformat;
        this.format = format;
        this.showgrades = showgrades;
        this.newsitems = newsitems;
        this.startdate = startdate;
        this.numsections = numsections;
        this.maxbytes = maxbytes;
        this.showreports = showreports;
        this.visible = visible;
        this.hiddensections = hiddensections;
        this.groupmode = groupmode;
        this.groupmodeforce = groupmodeforce;
        this.defaultgroupingid = defaultgroupingid;
        this.enablecompletion = enablecompletion;
        this.completionnotify = completionnotify;
        this.lang = lang;
        this.forcetheme = forcetheme;
        this.courseformatoptions = courseformatoptions;
    }

    /**
     * Constructor with MINIMAL set of parameters for new course creation through Web service.
     */
    public MoodleCourse(String fullname, String shortname, long categoryid) {
        this.shortname = shortname;
        this.categoryid = categoryid;
        this.fullname = fullname;
    }

    /**
     * Constructor for the objects, returned by createCourses method.
     */
    public MoodleCourse(long id, String shortname) {
        this.id = id;
        this.shortname = shortname;
    }

    /**
     * Course id.
     *
     * @return id of the course
     */
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    /**
     * Course short name.
     *
     * @return short name of the course
     */
    public String getShortname() {
        return shortname;
    }

    public void setShortname(String shortname) {
        this.shortname = shortname;
    }

    /**
     * Id of the course category.
     *
     * @return id of the course category
     */
    public long getCategoryid() {
        return categoryid;
    }

    public void setCategoryid(long categoryid) {
        this.categoryid = categoryid;
    }

    /**
     * Moodle course sorting order (long number) - used for arbitrary sorting of courses into the category in ascending
     * order of these numbers. This field is optional.
     *
     * @return course sorting order into the category
     */
    public long getCategorysortorder() {
        return categorysortorder;
    }

    public void setCategorysortorder(long categorysortorder) {
        this.categorysortorder = categorysortorder;
    }

    /**
     * Fullname of the course.
     *
     * @return fullname of the course
     */
    public String getFullname() {
        return fullname;
    }

    public void setFullname(String fullname) {
        this.fullname = fullname;
    }

    /**
     * Moodle course id number (additional unique id added for the course). This field is optional.
     *
     * @return course id number
     */
    public String getIdnumber() {
        return idnumber;
    }

    public void setIdnumber(String idnumber) {
        this.idnumber = idnumber;
    }

    /**
     * Moodle course brief description. This field is optional.
     *
     * @return course brief description
     */
    public String getSummary() {
        return summary;
    }

    public void setSummary(String summary) {
        this.summary = summary;
    }

    /**
     * Moodle course summary format (1 = HTML, 0 = MOODLE, 2 = PLAIN or 4 = MARKDOWN). Default=1. This field is
     * optional.
     *
     * @return course summary format
     */
    public byte getSummaryformat() {
        return summaryformat;
    }

    public void setSummaryformat(byte summaryformat) {
        this.summaryformat = summaryformat;
    }

    /**
     * Moodle course format: weeks, topics, social, site,.. Default = "topics". This field is optional.
     *
     * @return course format
     */
    public String getFormat() {
        return format;
    }

    public void setFormat(String format) {
        this.format = format;
    }

    /**
     * Moodle course show grades option = 1 if grades are shown, otherwise 0. Default=1. This field is optional.
     *
     * @return show grades option
     */
    public byte getShowgrades() {
        return showgrades;
    }

    public void setShowgrades(byte showgrades) {
        this.showgrades = showgrades;
    }

    /**
     * Number of recent news items appearing on the course page. Default=5. This field is optional.
     *
     * @return number of recent news items
     */
    public int getNewsitems() {
        return newsitems;
    }

    public void setNewsitems(int newsitems) {
        this.newsitems = newsitems;
    }

    /**
     * Timestamp when the course start. This field is optional.
     *
     * @return timestamp when the course start
     */
    public long getStartdate() {
        return startdate;
    }

    public void setStartdate(long startdate) {
        this.startdate = startdate;
    }

    /**
     * Number of weeks/topics of ther course(deprecated, use courseformatoptions). This field is optional.
     *
     * @return number of weeks/topics
     */
    public int getNumsections() {
        return numsections;
    }

    public void setNumsections(int numsections) {
        this.numsections = numsections;
    }

    /**
     * Largest size of file that can be uploaded into the course. Default=20971520. This field is optional.
     *
     * @return largest size of file that can be uploaded into the course
     */
    public long getMaxbytes() {
        return maxbytes;
    }

    public void setMaxbytes(long maxbytes) {
        this.maxbytes = maxbytes;
    }

    /**
     * Activity report show option (1 - report is shown, 0 - report is not shown). Default=1. This field is optional.
     *
     * @return activity report shown option
     */
    public byte getShowreports() {
        return showreports;
    }

    public void setShowreports(byte showreports) {
        this.showreports = showreports;
    }

    /**
     * Course visible for students option (1 - available to student, 0 - not available). This field is optional.
     *
     * @return visible for students option
     */
    public byte getVisible() {
        return visible;
    }

    public void setVisible(byte visible) {
        this.visible = visible;
    }

    /**
     * This option allows you to decide how the hidden sections in your course are displayed to students. You can
     * specify if hidden sections are shown in collapsed form (greyed out) or completely invisible to
     * students.(deprecated, use courseformatoptions). This field is optional.
     *
     * @return hidden sections option
     */
    public int getHiddensections() {
        return hiddensections;
    }

    public void setHiddensections(int hiddensections) {
        this.hiddensections = hiddensections;
    }

    /**
     * Course group mode option. No group = (there are no sub groups, everyone is part of one big community),
     * separate=(each group can only see their own group, others are invisible), visible=. (each group works in their
     * own group,but can also see other groups. (The other groups' work is read-only)). Default=2. This field is
     * optional.
     *
     * @return course group mode option
     */
    public byte getGroupmode() {
        return groupmode;
    }

    public void setGroupmode(byte groupmode) {
        this.groupmode = groupmode;
    }

    /**
     * Group mode force option. 1: yes, 0: no. Default=1. This field is optional
     *
     * @return group mode force option
     */
    public byte getGroupmodeforce() {
        return groupmodeforce;
    }

    public void setGroupmodeforce(byte groupmodeforce) {
        this.groupmodeforce = groupmodeforce;
    }

    /**
     * Id of groupings of Moodle groups. Default = 0. This field is optional
     *
     * @return id of groupings of Moodle groups
     */
    public long getDefaultgroupingid() {
        return defaultgroupingid;
    }

    public void setDefaultgroupingid(long defaultgroupingid) {
        this.defaultgroupingid = defaultgroupingid;
    }

    /**
     * Timestamp when the course have been created.
     *
     * @return timestamp of the course creation
     */
    public long getTimecreated() {
        return timecreated;
    }

    public void setTimecreated(long timecreated) {
        this.timecreated = timecreated;
    }

    /**
     * Timestamp when the course have been modified.
     *
     * @return timestamp of the course last modification
     */
    public long getTimemodified() {
        return timemodified;
    }

    public void setTimemodified(long timemodified) {
        this.timemodified = timemodified;
    }

    /**
     * Moodle course enable completion option. Enabled = 1, control via completion and activity settings. Disabled = 0,
     * not shown in activity settings. This field is optional.
     *
     * @return course enable completion option
     */
    public byte getEnablecompletion() {
        return enablecompletion;
    }

    public void setEnablecompletion(byte enablecompletion) {
        this.enablecompletion = enablecompletion;
    }

    /**
     * Moodle course completion notify option. 1: yes 0: no. This field is optional.
     *
     * @return course completion notify option
     */
    public byte getCompletionnotify() {
        return completionnotify;
    }

    public void setCompletionnotify(byte completionnotify) {
        this.completionnotify = completionnotify;
    }

    /**
     * Forced course language. This field is optional.
     *
     * @return forced course language
     */
    public String getLang() {
        return lang;
    }

    public void setLang(String lang) {
        this.lang = lang;
    }

    /**
     * Name of the course forced theme. This field is optional.
     *
     * @return course forced theme
     */
    public String getForcetheme() {
        return forcetheme;
    }

    public void setForcetheme(String forcetheme) {
        this.forcetheme = forcetheme;
    }

    /**
     * Additional options for the course format. This field is optional.
     *
     * @return additional options for the course format
     */
    public List<CourseFormatOption> getCourseformatoptions() {
        return courseformatoptions;
    }

    public void setCourseformatoptions(List<CourseFormatOption> courseformatoptions) {
        this.courseformatoptions = courseformatoptions;
    }

    @Override
    public String toString() {
        return "MoodleCourse{" + "id=" + id + ", shortname=" + shortname + ", categoryid=" + categoryid + ", categorysortorder=" + categorysortorder + ", fullname=" + fullname + ", idnumber=" + idnumber + ", summary=" + summary + ", summaryformat=" + summaryformat + ", format=" + format + ", showgrades=" + showgrades + ", newsitems=" + newsitems + ", startdate=" + startdate + ", numsections=" + numsections + ", maxbytes=" + maxbytes + ", showreports=" + showreports + ", visible=" + visible + ", hiddensections=" + hiddensections + ", groupmode=" + groupmode + ", groupmodeforce=" + groupmodeforce + ", defaultgroupingid=" + defaultgroupingid + ", timecreated=" + timecreated + ", timemodified=" + timemodified + ", enablecompletion=" + enablecompletion + ", completionnotify=" + completionnotify + ", lang=" + lang + ", forcetheme=" + forcetheme + ", courseformatoptions=" + courseformatoptions + '}';
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 41 * hash + Objects.hashCode(this.shortname);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final MoodleCourse other = (MoodleCourse) obj;
        if (!Objects.equals(this.shortname, other.shortname)) {
            return false;
        }
        return true;
    }

    @Override
    public int compareTo(MoodleCourse o) {
        int res = 0;
        if (o.getCategorysortorder() < this.getCategorysortorder()) {
            res = 1;
        }
        if (o.getCategorysortorder() > this.getCategorysortorder()) {
            res = -1;
        }
        return res;
    }
}
